package ${package.ServiceImpl};

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import com.zcb.scb.common.dto.PageParam;
import com.zcb.scb.common.dto.PageResult;
import com.zcb.scb.common.dto.Result;
import com.zcb.scb.common.utils.BeanCopierUtil;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
@Slf4j
public class ${table.serviceImplName} {

    @Resource
    private ${table.mapperName} ${table.entityPath}Dao;

    public Result<${entity}> get${entity}ById(Integer id) {
        log.info("${table.serviceImplName} get${entity}ById req={}", id);

        return new Result<>(${table.entityPath}Dao.get${entity}ById(id));
    }

    public Result<List<${entity}>> list${entity}(${entity} param) {
        log.info("${table.serviceImplName} list${entity} req={}", JSON.toJSONString(param));

        return new Result<>(${table.entityPath}Dao.list${entity}(param));
    }

	public Result<PageResult<${entity}>> pageList${entity}(PageParam<${entity}> param) {
        log.info("${table.serviceImplName} pageList${entity} req={}", JSON.toJSONString(param));

        Page<${entity}> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<${entity}> list = ${table.entityPath}Dao.pageList${entity}(param.getParam());

        PageResult<${entity}> pageResult = new PageResult<>(page, list);

        return new Result<>(pageResult);
    }

    @Transactional
    public Result<Integer> add${entity}(${entity} entity) {
        log.info("${table.serviceImplName} add${entity} req={}", JSON.toJSONString(entity));

        //${table.comment!}
        //${entity} entity = BeanCopierUtil.copyProperties(dto, ${entity}.class);

        Integer i = ${table.entityPath}Dao.add${entity}(entity);
        return new Result<>(i);
    }

    @Transactional
    public Result<Integer> upd${entity}(${entity} entity) {
        log.info("${table.serviceImplName} upd${entity} req={}", JSON.toJSONString(entity));

        //${table.comment!}
        //${entity} entity = BeanCopierUtil.copyProperties(dto, ${entity}.class);

        Integer i = ${table.entityPath}Dao.upd${entity}(entity);
        return new Result<>(i);
    }


    @Transactional
    public Result<Integer> del${entity}(${entity} dto) {
        log.info("${table.serviceImplName} del${entity} req={}", JSON.toJSONString(dto));

        Integer i = ${table.entityPath}Dao.del${entity}(dto.getId());
        return new Result<>(i);
    }

    <#--/**
    * 根据id删除${entity}
    */
    @Transactional
    public Result<Integer> delete${entity}ById(Long id) {
        Integer i = 0;
        try {
            i = ${table.entityPath}Dao.delete${entity}ById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result<>(i);
    }-->
}
